<?php 
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Session;
class Masterquestion extends Controller
{
	public function index(){
		$this->checkLogin();
	    $m=Db::table('masterquestion')
		->alias('mq')
		->join('users u','mq.user_id = u.user_id')
		->join('master m','mq.master_id = m.master_id')
		->select();
		$count = count($m);
        $this->assign('masterquestion',$m);    
        $this->assign('count',$count);    
        return $this->fetch();
		
	}

	public function delete($id){
		$this->checkLogin();
		$masterquestion=Db::name("masterquestion")->find($id);
		if(Db::name("masterquestion")->delete($id))
			$this->success('删除成功');
		else $this->error('删除失败');
	}

	public function search () {
		$this->checkLogin();
		$content = input('content');
	    $m=Db::table('masterquestion')
		->alias('mq')
		->join('users u','mq.user_id = u.user_id')
		->join('master m','mq.master_id = m.master_id')
        ->where('user_name','like','%'.$content.'%')
		->select();
		$count = count($m);
        $this->assign('masterquestion',$m);    
        $this->assign('count',$count);    
        return $this->fetch('index');
	}
}